package com.wn.config;

import com.wn.intercepter.JwtInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author yellow Docter
 * @date 2022 -06-10
 * @desc
 *   注册 mvc 的拦截器
 *
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    // 注册
    @Bean
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 给jwt指定拦截规则 未来以/api/开头的资源接口全部要token鉴权
        registry.addInterceptor(jwtInterceptor()).addPathPatterns("/api/**");
    }
}